package com.lcw.android.scrollsplitview;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.lcw.android.scrollsplitview.widget.VerticalDrawerControlLayout;

/**
 * @author lcw
 * @date 2021/3/24
 * @desc
 */
public class VerticalDrawerControlActivity extends AppCompatActivity {

    private ImageView handler;
    private Button controlBtn;
    private VerticalDrawerControlLayout verticalDrawerControlLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vertical_drawer_control);
        handler = findViewById(R.id.handler);
        controlBtn = findViewById(R.id.controlBtn);
        handler.setVisibility(View.INVISIBLE);
        verticalDrawerControlLayout = findViewById(R.id.verticalDrawerControlLayout);
        verticalDrawerControlLayout.setOnDragCallback(new VerticalDrawerControlLayout.onDragCallback() {
            @Override
            public void onDrag(float scroll) {
                Log.e("changwen", "scroll =  " + scroll);
                Log.e("changwen", "scroll3333 =  " + (int) (scroll * 255));
                handler.setAlpha((int) (scroll * 255));
                if (scroll == 0) {
                    handler.setVisibility(View.INVISIBLE);
                    controlBtn.setSelected(false);
                } else {
                    handler.setVisibility(View.VISIBLE);
                    controlBtn.setSelected(true);
                }
            }
        });
    }

    public void onOpen(View view) {
        if (controlBtn.isSelected()) {
            controlBtn.setSelected(false);
            verticalDrawerControlLayout.closeDrawer();
        } else {
            controlBtn.setSelected(true);
            verticalDrawerControlLayout.openDrawer();
        }
//        if (verticalDrawerControlLayout.isDrawerOpened()) {
//            verticalDrawerControlLayout.closeDrawer();
//        } else {
//            verticalDrawerControlLayout.openDrawer();
//        }
    }

}
